package com.printeverywhere.action.MailCenter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.printeverywhere.delegator.MailServerDelegator;
import com.printeverywhere.dto.MailServer;

public class GetMailDetailsAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private String userId = "1";
	private List<MailServer> inboxlist = new ArrayList<MailServer>();
	private List<MailServer> outboxlist = new ArrayList<MailServer>();	
	private List<MailServer> message = new ArrayList<MailServer>();
	
	public List<MailServer> getMessage() {
		return message;
	}

	public void setMessage(List<MailServer> message) {
		this.message = message;
	}

	public List<MailServer> getInboxlist() {
		return inboxlist;
	}

	public void setInboxlist(List<MailServer> inboxlist) {
		this.inboxlist = inboxlist;
	}

	public List<MailServer> getOutboxlist() {
		return outboxlist;
	}

	public void setOutboxlist(List<MailServer> outboxlist) {
		this.outboxlist = outboxlist;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	
	public String getMailDetails() {
		
		try {
			List<MailServer> list = MailServerDelegator.getMailDetails(userId);
			
			System.out.println("size:- "+list.size());			
						
			Iterator<MailServer> it = list.iterator();
			int i=1;
			while(it.hasNext())
			{
				int j = i -1;
				MailServer dto = list.get(j);				
				if(dto.getIsEmail().equals("1")) {
					if(dto.getType().equalsIgnoreCase("inbox"))
						inboxlist.add(list.get(j));
					else if(dto.getType().equalsIgnoreCase("outbox"))
						outboxlist.add(list.get(j));					
				}
				else if (dto.getIsMessage().equals("1")) { 
					message.add(list.get(j));
				}
				i++;
				if(j + 1 == list.size())
					break;
			}
		}
		catch(Exception e) {
			System.out.println(e);
		}
		
		return SUCCESS;
	}

	
}
